<?php
class MemberController extends CommonController{
	
	private $_model;
	public function __init(){
		$this->_model = K('Member');
//		p($this->_model);
	}
	
	
	public function index(){
		
		$this->dis('index');
	}
	
	
	//前台登录
	public function login(){
		if(isset($_SESSION['aid']) && isset($_SESSION['username'])){
			go('Index/index');
		}
		
		if(IS_POST){
//			$model=K('Member');
//			p($_POST);die;
//			p($_SESSION);die;
			if(!$data = $this->_model->validate_login()){
				$this->error($this->_model->error);
			}
			//登录成功存到session里
			session('aid',$data['uid']);
			session('username',$data['username']);
			$this->success('登录成功',U('index/index'));
			
		}
		
		$this->dis('login');
	}
	
	
	//前台注册
	public function register(){
		if(IS_POST){
//$m=K('Member');var_dump($m);die;
			//执行验证
			if(!$data = $this->_model->validate_register()) 
			$this->error($this->_model->error);

			$this->success('注册成功',U('Index/index'));
		
		}
		$this->dis('register');
	
	}
	//退出
	public function out(){
		session(NULL);
		$this->success('退出成功');
	}
	
	
	
	
	
	
		
}